package flexo.graphic;

import flexo.common.ResourcePool;

public class GeometryPool extends ResourcePool
{
	/**
	 * Returns the geometry specified with the 'resourceName'.
	 * If theres no geometry associated with the name, null is returned.
	 */
	public Geometry get(String resourceName)
	{
		return (Geometry)super.get(resourceName);
	}
	
	public Geometry getQuad(float width, float height)
	{
		String id = "$quad[" + width + "," + height + "]";
		Geometry q = get(id);
		if (q == null)
		{
			q = GeometryLoader.createQuad(width, height);
			add(id,q);
		}
		return q;
	}
	
	public Geometry getTerrain(String heightMap, flexo.math.Coords size, flexo.math.Coords points,float maxHeight)
	{
		String id = "$terrain[heightMap,"+size.x+","+size.y+","+points.x+","+points.y+"]";
		Geometry ret = get(id);
		if (ret == null)
		{
			ret = GeometryLoader.createTerrain(heightMap,size,points,maxHeight);
			add(id,ret);
		}
		return ret;
	}
	
	public Geometry getObj(String fileName)
	{
		flexo.file.FileSystem fs = (flexo.file.FileSystem)flexo.Kernel.getSystem(flexo.file.FileSystem.ID);
		String id = fs.getFullPath(fileName);
		Geometry q = get(id);
		if (q == null)
		{
			q = GeometryLoader.createObj(id);
			add(id,q);
		}
		return q;
	}
}
